//
//  ShowMainView.m
//  YepaoFitness
//
//  Created by 震霄 张 on 2017/7/13.
//  Copyright © 2017年 neo. All rights reserved.
//

#import "ShowMainView.h"

#import "MBProgressHUD.h"


@interface ShowMainView()<AcvQequestViewDelegate>

@property (nonatomic,copy)void (^didMakeSure)(NSString *name,NSString *des,BOOL open);

@end

@implementation ShowMainView
static ShowMainView *_alertV;



+ (void)showWithMsg:(NSString *)msg {
//    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
//    hud.mode = MBProgressHUDModeText;
//    hud.label.text = NSLocalizedString(msg, @"HUD message title");
//    hud.offset = CGPointMake(0.f, MBProgressMaxOffset);
//    [hud hideAnimated:YES afterDelay:1.f];
//
    MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:[UIApplication sharedApplication].keyWindow animated:YES];
    hud.mode = MBProgressHUDModeText;
    hud.labelText =NSLocalizedString(msg, @"HUD message title");
    [hud hide:YES afterDelay:1.f];

    
}


-(void)dealloc
{
    NSLog(@"_alert被销毁了");
}

+(void)showAcvQequest:(NSString *)oldName des:(NSString *)oldDes open:(BOOL)oldOpen WithAction:(void(^)(NSString *name,NSString *des,BOOL open))click
{
    [self initialBackgroundWithAlpha:0.4];
	
	AcvQequestView *shwView = [AcvQequestView acvQequestView];
    shwView.frame = CGRectMake(0, 0, 300, 200);
    shwView.delegate = _alertV;
//    [self setMainVFrame:shwView];
	shwView.centerX = screen_Width * .5;
	shwView.centerY = screen_Height * .5 - 100;
	
	shwView.name = oldName;
	shwView.des = oldDes;
	shwView.open = oldOpen;
    [_alertV addSubview:shwView];
    _alertV.hidden = NO;
    _alertV.didMakeSure = click;
}

+(void)showWithTitle:(NSString *)title subTitle:(NSString *)subT makesureAction:(void (^)())click
{
    [self initialBackgroundWithAlpha:0.4];
    
//    CangActionInfoView *infoView = [CangActionInfoView cangActionInfoView];
//    infoView.titleSTr = title;
//    infoView.subTitleSTr = subT;
//    infoView.frame = CGRectMake(0, 0, SCREEN_W-40, 180);
//    infoView.delegate = _alertV;
//    [self setMainVFrame:infoView];
////    [_alertV addSubview:infoView];
//    _alertV.hidden = NO;
//    _alertV.didMakeSure = click;
}

+(void)showWithTitle:(NSString *)title subTitle:(NSString *)subT yesTitle:(NSString *)yt noTitle:(NSString *)noTitle makesureAction:(void (^)())click
{
    [self initialBackgroundWithAlpha:0.4];
    
//    CangActionInfoView *infoView = [CangActionInfoView cangActionInfoView];
//    infoView.titleSTr = title;
//    infoView.subTitleSTr = subT;
//    infoView.YestitleSTr = yt;
//    infoView.NotitleSTr = noTitle;
//    infoView.frame = CGRectMake(0, 0, SCREEN_W-40, 180);
//    infoView.delegate = _alertV;
//    [self setMainVFrame:infoView];
//    [_alertV addSubview:infoView];
//    _alertV.hidden = NO;
//    _alertV.didMakeSure = click;
}


+ (void)initialBackgroundWithAlpha:(CGFloat)alpha {
    _alertV = [[self alloc] initWithFrame:[UIScreen mainScreen].bounds];
    //    _alertV.rootViewController = [[UIViewController alloc] init];
    _alertV.windowLevel = UIWindowLevelAlert;
    UIView *alphaView = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
    alphaView.backgroundColor = [UIColor blackColor];
    alphaView.alpha = alpha;
    [_alertV addSubview:alphaView];
    
}


+ (void)setMainVFrame:(UIView *)mainView {
    mainView.centerX = screen_Width * .5;
    mainView.centerY = screen_Height * .5;
    
}

#pragma mark delegate
-(void)cancelQequest
{
	self.hidden = YES;
	_alertV = nil;
}

-(void)makeSureQequest:(NSString *)name info:(NSString *)des isOPen:(BOOL)open
{
	_alertV.didMakeSure(name, des, open);
	self.hidden = YES;
	_alertV = nil;
}


@end
